package haust;

import static org.lwjgl.opengl.GL11.*;

import java.awt.Font;
import java.io.InputStream;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.util.ResourceLoader;

public class FontManager {
	private static TrueTypeFont font;
	
	/**
	 * 
	 */
	static void loadFont()	{
     
    	// load font from a .ttf file
    	try {
    		InputStream inputStream	= ResourceLoader.getResourceAsStream("fonts/SamsonBold.ttf");
     		Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
    		awtFont = awtFont.deriveFont(28f); // set font size
    		font = new TrueTypeFont(awtFont, false);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}	
    }
	
    /**
     * Draws a text with a predefined font, draws the font on the 2D plane.
     * Designed to be called between pushOrtho() and popOrtho().
     * @param text
     * @param x
     * @param y
     */
    public static void drawTextFont(String text,float x,float y){
    	glPushMatrix();
    	glScalef(1,-1,1);
    	
    	glEnable(GL11.GL_BLEND);
        glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    	font.drawString(x, -y, text,Color.yellow);
    	glColor3f(1, 1, 1);
    	glDisable(GL11.GL_BLEND);
    	
    	glPopMatrix();
    }
}
